package org.example.BIO_03;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Socket;

public class SocketHandler extends Thread{
    private Socket socket;

    public SocketHandler(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        InputStream is = null;
        try {
            is = socket.getInputStream();
            // 转为缓冲字符流
            BufferedReader bf = new BufferedReader(new InputStreamReader(is));
            // 阻塞等待消息并接收
            String msg;
            while((msg = bf.readLine()) != null) {
                System.out.println("服务端接收到消息："+ msg);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
